<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <script type="text/javascript" src="/js/cookie.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="/js/html5.min.js"></script>
    <script src="/js/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="javascript:;">首页</a>
        <a href="javascript:;">服务器管理</a>
        <a>
          <cite>主机管理</cite>
        </a>
    </span>
    <span class="x-right">
        <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ</i>
        </a>
    </span>

</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
            <input type="text" name="name" placeholder="请输入主机名" value="${vo.name!''}" autocomplete="off"
                   class="layui-input">

            <div class="layui-input-inline">
                <select name="groupId">
                    <option value="">主机分组</option>
                    <#list listGroups as group>
                        <option value="${group.id}"
                                <#if vo.groupId?? && vo.groupId==group.id>selected</#if>>${group.name}</option>
                    </#list>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="authId">
                    <option value="">认证密钥</option>
                    <#list listAuths as auth>
                        <option value="${auth.id}"
                                <#if vo.authId?? && vo.authId==auth.id>selected</#if>>${auth.name}</option>
                    </#list>
                </select>
            </div>
            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>

    <xblock>
        <div class="x-right">
            <button class="layui-btn layui-btn-danger" onclick="deleteBatch()"><i class="layui-icon"></i>批量删除</button>
            <button class="layui-btn" onclick="x_admin_show('添加主机','/host/info/edit.htm',500,500)">
                <i class="layui-icon"></i>添加
            </button>
        </div>
        <div style="clear:both;"></div>
    </xblock>
    <table class="layui-table x-admin">
        <thead>
        <tr>
            <th width="30">
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary">
                    <i class="layui-icon">&#xe605;</i>
                </div>
            </th>
            <th>编号</th>
            <th>主机名</th>
            <th>分组</th>
            <th>认证密钥</th>
            <th>主机地址</th>
            <th>端口</th>
            <th>操作系统</th>
            <th>备注说明</th>
            <th width="140">操作</th>
        </tr>
        </thead>
        <tbody>
        <#list listData as row>
        <tr>
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='${row.id}'>
                    <i class="layui-icon">&#xe605;</i>
                </div>
            </td>
            <td>${row.id}</td>
            <td>${row.name}</td>
            <td><#if row.hostGroup??>${row.hostGroup.name}<#else>-</#if></td>
            <td><#if row.hostAuth??>${row.hostAuth.name}<#else>-</#if></td>
            <td>${row.hostAddress}</td>
            <td>${row.portNumber}</td>
            <td>${row.os}</td>
            <td>${row.remark!''}</td>
            <td class="td-manage">
                <a title="打开终端" href="javascript:;"
                   onclick="openTerminal('${row.name}',${row.id})"
                   style="color: red">
                    <i class="iconfont">&#xe6ee;</i>
                    打开终端
                </a>

                <a title="打开终端" href="javascript:;"
                   onclick="x_admin_show('修改主机','/host/info/edit.htm?id=${row.id}',500,500)"
                   style="color: blue">
                    <i class="iconfont">&#xe69e;</i>
                    修改
                </a>
            </td>
        </tr>
        </#list>
        </tbody>
    </table>
    ${showPaginator(paginator)}
</div>
<script>
    var openTerminal = function (name, hostId) {
        parent.x_admin_add_to_tab(name, '/terminal/' + hostId + '/${accessToken}.htm?_=' + Math.random(), false);
    };

    var deleteBatch = function () {
        var data = tableCheck.getData();
        if (data.length <= 0) {
            layer.msg('请选择要删除的记录');
        }
        layer.confirm('确认要删除吗？', function (index) {
            //捉到所有被选中的，发异步进行删除
            $(".layui-form-checked").not('.header').parents('tr').remove();

            $.post("/host/info/delete.ajax", {ids: data.join(",")}, function (result) {
                window.location.reload();
            });
        });
    };
</script>
</body>

</html>